Optimize recursive calls