slicing and memoization