Fixes to make it run on Python 3 and a little cleanup

Just some minor improvements.