fixed the depth-sorting issues that resulted from the previous optimization