Improved deque implementation