added memoize method to cache function responses.