buggy code for linklist sorting