Massive refactor part 1