[RFC] Refactor codebase

cc @mlubin @IainNZ