use deque instead of reversed lists