How comparator actually works??