Massive refactor of everything