Some pep8 fixes + some bugfixes