Cleanup and re-org

Split up the file into partials to help my sanity. Moved some constants
and stuff into separate files.