Fix endUpdates sort issue

I got strange crashes when running endUpdates, so I looked into the code and the sort method looked incorrect. This change this fixed my crashes.