implementation with deque