Modified for loop that creates the linked list