Huge refactor: entire codebase in PEP8, imports alphabetized, bugfixes, core changes

I'd like an extra pair of eyes on this pull request before it gets merged. The testing suite and a few dry runs work just fine but there are not enough tests to cover every code path. 

This was meant to be a huge refactor but there were also quite a few bugfixes & core changes
that happened.

Some notable lines that have been changed: