added reference_id sorting