[RFC] Refactor codebase

cc @mlubin @IainNZ 
That's fine also.