Optimization with doubly linked list