Source formatting improvements

This commit introduces many formatting improvements. There are no
functional changes to the code, the only changes are that it was made
prettier with come python code linters (flake8, pep8, and mccabe).