sort functions and linked list improved