Refactors some stuff to make it less coupled. Not completely functional yet, but had to stop due to real work.