Filled out sortUnitsByDepth() method