Started major refactoring (unfinished)