Refactored in preparation to update to priority q