replaced vector by deque to optimize performance