Revise entity sorting

Sort entities in a saner maner.