refactoring code, due to removal of LinkedList implementation