Implement queue as priority queue and other changes