Code cleanups, code style improvements, etc

This is a first bunch of changes, which hopefully will make the code look more pythonic and a bit cleaner.