multi-step sorting of rows