Added code to use memonization pattern to improve performance