Massive refactor. Moved everything out of core into reasonable namespaces.