Major refactor merge