[RFC] Refactor codebase

cc @mlubin @IainNZ 
Is this formula only for maximization?