attempt to pep8tify

This code is badly written. Hope to do a complete re-write in the future