Added sort parameter for recursive calls