Refactoring codebase, still a major WIP