Fixed NULL pointer dereferencing in linked lists