Moved MemoizedFunction<> to header.
Removed unneeded cast.