Finish refactoring to remove circular dependencies and misc. other stuff