Major refactor. More refactors to come