ensure entities are sorted