Removed unneeded sortByDepth loop function