added priority queue and debugged