Massive refactor - still testing