Implemented memoization / caching of functions.