Extract rich_sort? method
Extract have_records? method
Rename have_records? to has_records?
Extract calculate_sort_offset! method
Extract calculate_output_offset! method
Extract final_offset method