Optimize order of recursive calls