PEP8 cleanup and fixing bugs