Use deque for state stacks