[RFC] Refactor codebase

cc @mlubin @IainNZ 
Maybe we should just implement this in a consistent and generic way, because different solvers might have slightly different definitions of the gap.