Factored out eval function