Implemented memoization. Uses too much ram, and might be buggy.
Make memoization a compile time option.
spelling fix