Removed deque insert after to avoid code duplication