optimized comparator for better speed