Error fix and format code to pep8