Implement queue with O(1) operations, and correct some math.