Misc fixes and cosmetics

Hi,

I've found a few oddities in this module so I went ahead and fixed them.

I also ran the code through pep8 and pylint to clean things up a bit, enjoy.