Some reorganization and refactoring of code

Redid some bad bits and made some less bad bits even less bad