sorting 1st phase