Implementing much of smart-eval.