Fixes to sorting in ReferencePosition