More Solver tidying

Moved some of the build_problem logic into separate top-level functions.