WIP

Lots of data structure refactoring