Make this work with Python 3, and do some minor cleanup

* Works with Python 3.3.5 and 2.7.7