Restructured evaluate-function to factor out environment