first part of sorting done