Cleaned up a bit: PEP8-ed, added docstrings, added logging, removed unnecessary code