replace Stack with Deque