added Gagravarr's change to support Python 2.6.x and 2.7.x. Also cleaned up the file