Pep8 and globals creanup

I've cleaned up the code a little bit, largely as an effort to understand it better for further development purposes. These changes all make the code conform to pep8 standards. The list of globals definitions makes it easier for future readers to understand. I do not believe I made any functional changes here, but the final commit, (9b8aaf0 the has_key change), may break compatibility with ancient pythons, I'm not certain.