Added formatting function with tests, and a bunch of pylint cleanup.
Some flake8 improvements.