Ensures all memo keys are hashable

Also makes memoization configurable.