Major code reorg

Reorganized the code so it is a lot cleaner, also added some sweet
comments so that everything makes (a little) more sense