Refactoring/Cleanup of smt.ml

Most of this straight-forward lifting to higher-order methods. I'm happy to reformat/restyle, if you want to enforce a certain style :-)