A bunch of reordering things and refactoring
Merge changes