Ok this looks pretty good now, should refactor before merging back to master
Heavy refactoring