Used a Deque rather than Stack