Big refactor

WIP