Issue #4: Optimize the evaluation of functions

Get the eval function out of the loop.