Replace deque with list for better memory management (note: always use the simplest container possible)