fixed logic for duplicate consecutive entries