simplifying cacheSolve's logic