Fix doctest, pep8, and flake8 errors