Makes pep8 like the code, fixes some minor bugs.