This code is more elegant
diff --git a/abstract_factory.py b/abstract_factory.py
index 7ecf0fc3..72d57043 100644
--- a/abstract_factory.py
+++ b/abstract_factory.py
@@ -7,20 +7,17 @@
 
 import random
 
-
 class PetShop:
 
     """A pet shop"""
 
     def __init__(self, animal_factory=None):
-        """pet_factory is our abstract factory.
-        We can set it at will."""
+        """pet_factory is our abstract factory.  We can set it at will."""
 
         self.pet_factory = animal_factory
 
     def show_pet(self):
-        """Creates and shows a pet using the
-        abstract factory"""
+        """Creates and shows a pet using the abstract factory"""
 
         pet = self.pet_factory.get_pet()
         print("We have a lovely {}".format(pet))
@@ -55,19 +52,12 @@ class DogFactory:
     def get_pet(self):
         return Dog()
 
-    def get_food(self):
-        return "dog food"
-
 
 class CatFactory:
 
     def get_pet(self):
         return Cat()
 
-    def get_food(self):
-        return "cat food"
-
-
 # Create the proper family
 def get_factory():
     """Let's be dynamic!"""
@@ -76,9 +66,8 @@ def get_factory():
 
 # Show pets with various factories
 if __name__ == "__main__":
-    shop = PetShop()
     for i in range(3):
-        shop.pet_factory = get_factory()
+        shop = PetShop(get_factory())
         shop.show_pet()
         print("=" * 20)
 
diff --git a/adapter.py b/adapter.py
index 2db7faa1..1620ce4c 100644
--- a/adapter.py
+++ b/adapter.py
@@ -5,39 +5,28 @@
 
 import os
 
-
 class Dog(object):
-
     def __init__(self):
         self.name = "Dog"
-
     def bark(self):
         return "woof!"
 
-
 class Cat(object):
-
     def __init__(self):
         self.name = "Cat"
-
     def meow(self):
         return "meow!"
 
-
 class Human(object):
-
     def __init__(self):
         self.name = "Human"
-
     def speak(self):
         return "'hello'"
 
 
 class Car(object):
-
     def __init__(self):
         self.name = "Car"
-
     def make_noise(self, octane_level):
         return "vroom{0}".format("!" * octane_level)
 
diff --git a/chain.py b/chain.py
index 37cad8d9..6698f8f9 100644
--- a/chain.py
+++ b/chain.py
@@ -3,69 +3,50 @@
 
 """http://www.testingperspective.com/wiki/doku.php/collaboration/chetan/designpatternsinpython/chain-of-responsibilitypattern"""
 
-
 class Handler:
-
-    def __init__(self):
-        self._successor = None
-
-    def successor(self, successor):
-        self._successor = successor
-
-    def handle(self, request):
+    def __init__(self,successor):
+        self._successor = successor;
+    def handle(self,request):
+        i = self._handle(request)
+        if  not i:
+            self._successor.handle(request)
+    def _handle(self, request):
         raise NotImplementedError('Must provide implementation in subclass.')
 
 
 class ConcreteHandler1(Handler):
 
-    def handle(self, request):
+    def _handle(self, request):
         if 0 < request <= 10:
             print('request {} handled in handler 1'.format(request))
-        elif self._successor:
-            self._successor.handle(request)
-
-
+            return True
+            
 class ConcreteHandler2(Handler):
-
-    def handle(self, request):
+    
+    def _handle(self, request):
         if 10 < request <= 20:
             print('request {} handled in handler 2'.format(request))
-        elif self._successor:
-            self._successor.handle(request)
-
-
+            return True
+        
 class ConcreteHandler3(Handler):
-
-    def handle(self, request):
+    
+    def _handle(self, request):
         if 20 < request <= 30:
             print('request {} handled in handler 3'.format(request))
-        elif self._successor:
-            self._successor.handle(request)
-
-
+            return True
 class DefaultHandler(Handler):
-
-    def handle(self, request):
-            print('end of chain, no handler for {}'.format(request))
+    
+    def _handle(self, request):
+        print('end of chain, no handler for {}'.format(request))
+        return True
 
 
 class Client:
-
     def __init__(self):
-        h1 = ConcreteHandler1()
-        h2 = ConcreteHandler2()
-        h3 = ConcreteHandler3()
-        h4 = DefaultHandler()
-
-        h1.successor(h2)
-        h2.successor(h3)
-        h3.successor(h4)
-
-        self.handlers = (h1, h2, h3, h4,)
-
+        self.handler = ConcreteHandler1(ConcreteHandler3(ConcreteHandler2(DefaultHandler(None))))
     def delegate(self, requests):
         for request in requests:
-            self.handlers[0].handle(request)
+            self.handler.handle(request)
 
 
 if __name__ == "__main__":
diff --git a/command.py b/command.py
index 9aab10f6..727f42cb 100644
--- a/command.py
+++ b/command.py
@@ -11,9 +11,6 @@ def __init__(self, src, dest):
         self.dest = dest
 
     def execute(self):
-        self()
-
-    def __call__(self):
         print('renaming {} to {}'.format(self.src, self.dest))
         os.rename(self.src, self.dest)
 
diff --git a/composite.py b/composite.py
index 9b8cc56f..d49fc55b 100644
--- a/composite.py
+++ b/composite.py
@@ -5,11 +5,10 @@
 A class which defines a composite object which can store
 hieararchical dictionaries with names.
 
-This class is same as a hiearchical dictionary, but it
-provides methods to add/access/modify children by name,
-like a Composite.
+This class is same as a hiearchical dictionary, but it provides methods
+to add/access/modify children by name, like a Composite.
 
-Created Anand B Pillai     <abpillai@gmail.com>
+Created Anand B Pillai <abpillai@gmail.com>
 
 """
 __author__ = "Anand B Pillai"
@@ -18,8 +17,10 @@
 
 
 def normalize(val):
-    """ Normalize a string so that it can be used as an attribute
-    to a Python object """
+    """Normalize a string so that it can be used as an attribute to a Python
+
+    object
+    """
 
     if val.find('-') != -1:
         val = val.replace('-', '_')
@@ -38,8 +39,7 @@ def denormalize(val):
 
 class SpecialDict(dict):
 
-    """ A dictionary type which allows direct attribute
-    access to its keys """
+    """A dictionary type which allows direct attribute access to its keys """
 
     def __getattr__(self, name):
 
@@ -127,11 +127,13 @@ def isLeaf(self):
         return not self._children
 
     def getName(self):
+        
         """ Return the name of this ConfigInfo object """
 
         return self._name
 
     def getIndex(self, child):
+        
         """ Return the index of the child ConfigInfo object 'child' """
 
         if child in self._children:
@@ -145,17 +147,17 @@ def getDict(self):
         return self[self._name]
 
     def getProperty(self, child, key):
-        """ Return the value for the property for child
-        'child' with key 'key' """
+        
+        """Return the value for the property for child 'child' with key 'key' """
 
         # First get the child's dictionary
         childDict = self.getInfoDict(child)
         if childDict:
             return childDict.get(key, None)
 
-    def setProperty(self, child, key, value):
-        """ Set the value for the property 'key' for
-        the child 'child' to 'value' """
+        def setProperty(self, child, key, value):
+            
+            """Set the value for the property 'key' for the child 'child' to 'value' """
 
         # First get the child's dictionary
         childDict = self.getInfoDict(child)
@@ -163,11 +165,13 @@ def setProperty(self, child, key, value):
             childDict[key] = value
 
     def getChildren(self):
+        
         """ Return the list of immediate children of this object """
 
         return self._children
 
     def getAllChildren(self):
+        
         """ Return the list of all children of this object """
 
         l = []
@@ -178,6 +182,7 @@ def getAllChildren(self):
         return l
 
     def getChild(self, name):
+        
         """ Return the immediate child object with the given name """
 
         for child in self._children:
@@ -185,6 +190,7 @@ def getChild(self, name):
                 return child
 
     def findChild(self, name):
+        
         """ Return the child with the given name from the tree """
 
         # Note - this returns the first child of the given name
@@ -196,6 +202,7 @@ def findChild(self, name):
                 return child
 
     def findChildren(self, name):
+        
         """ Return a list of children with the given name from the tree """
 
         # Note: this returns a list of all the children of a given
@@ -210,6 +217,7 @@ def findChildren(self, name):
         return children
 
     def getPropertyDict(self):
+        
         """ Return the property dictionary """
 
         d = self.getChild('__properties')
@@ -219,6 +227,7 @@ def getPropertyDict(self):
             return {}
 
     def getParent(self):
+        
         """ Return the person who created me """
 
         return self._father
diff --git a/foo.txt b/foo.txt
deleted file mode 100644
index 5aecc849..00000000
--- a/foo.txt
+++ /dev/null
@@ -1 +0,0 @@
-All krakens crush undead, evil sails.
diff --git a/iterator.py b/iterator.py
deleted file mode 100644
index 3aa36b8d..00000000
--- a/iterator.py
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-"""http://ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/
-
-Implementation of the iterator pattern with a generator"""
-
-
-def count_to(count):
-    """Counts by word numbers, up to a maximum of five"""
-    numbers = ["one", "two", "three", "four", "five"]
-    # enumerate() returns a tuple containing a count (from start which
-    # defaults to 0) and the values obtained from iterating over sequence
-    for pos, number in zip(range(count), numbers):
-        yield number
-
-# Test the generator
-count_to_two = lambda: count_to(2)
-count_to_five = lambda: count_to(5)
-
-print('Counting to two...')
-for number in count_to_two():
-    print(number, end=' ')
-
-print()
-
-print('Counting to five...')
-for number in count_to_five():
-    print(number, end=' ')
-
-print()
-
-### OUTPUT ###
-# Counting to two...
-# one two
-# Counting to five...
-# one two three four five
diff --git a/publish_subscribe.py b/publish_subscribe.py
index e88dd4f3..522e9ea4 100644
--- a/publish_subscribe.py
+++ b/publish_subscribe.py
@@ -10,9 +10,8 @@
 class Provider:
 
     def __init__(self):
-        self.msg_queue = []
-        self.subscribers = {}
-
+        self.subscribe_queue = {}
+        self.msg_queue=[]
     def notify(self, msg):
         self.msg_queue.append(msg)
 
@@ -25,12 +24,14 @@ def subscribe(self, msg, subscriber):
 
     def unsubscribe(self, msg, subscriber):
         self.subscribers[msg].remove(subscriber)
+        if !self.subscribe[msg]:
+            del self.subscribe[msg]
 
     def update(self):
         for msg in self.msg_queue:
-            if msg in self.subscribers:
-                for sub in self.subscribers[msg]:
-                    sub.run(msg)
+            if msg in self.subscribers.keys():
+                for suber in self.subscribers[msg]:
+                    suber.get(msg)
         self.msg_queue = []
 
 
@@ -52,7 +53,7 @@ def __init__(self, name, msg_center):
     def subscribe(self, msg):
         self.provider.subscribe(msg, self)
 
-    def run(self, msg):
+    def get(self, msg):
         print("{} got {}".format(self.name, msg))
 
 

output has not changed
