Bug fixes and Pep8