Linked list fixes, memory leak fixes