Refactor out cached evaluation a bit
Rewrite evaluation code and add test suite (#19)