sort collections before iterating over them