Added some code for memoising the evaluate() fn, but not used yet because still possibly slower. Ignore underflow errors.