fixing bugs and pep8 compatibility