fixed row sorting error that affected cost calculation