refactored code to be consistent with LinkedList