fix priority queue logic
add test