First sort implementatin