add sorting and priority queue