refactoring - delicate caching for the closures
refactoring and  memoize function for reduce
no need to enlist exceptions occured