fix a horrible deque bug, add lots of tests