Refactor function evaluation.

Change-Id: I1e305111c864d1ee8289c470af11738b8a3afb8f