Implemented most of queue.