reference_id sorting fix