Changed stack to deque