Clean up and pep8 as far as I can all the code here.