Rephrased the memoization method for better syntax