Pythonic code style. Typos. Removed redundant code.

This is identical to to previous (now closed) pull request, except that the changes aren't on the master branch.

This pull request addresses various code style and clean-up issues as flagged by the Python static analysis tools in PyCharm as well as some general stylistic issues which make the code more 'Pythonic'. I think the code is better as a result as well as being functionally identical.