Fix test cases and pep8