Began major refactoring, currently a broken build.
Ugly merge.