Refactored the generic implementation of LinkedList