logic update and bug fix for comparator