refactored to use ArrayList instead of PriorityQueue