factored out comparator definition