Major refactor part 2