refactor / comment / bug fixes

Refactored common functionality into util.py and common data into config.py. Improved & PEP-ified comments and fixed miscellaneous bugs.