add depth sorting algorithm