optimized memoize so that it can take any number of arguments