Sorting improvements

mprove sorting of types and resources