fix bugs and finish deque