added memoize fn + many small revisions