optimize maxWithTies to work with PriorityQueues
cleanup