Updated insertion sort and output formatting