Move some code, and fix pep8 things