Made comparator serializable so that caching works.