sort in loop