Finish refactor of core code