wrote auto memoizer
cleaned up code