Fixed Depth Sorting

also fixed a few crashes