added caching to my algorithm