Major refactor of everything