Adding logic for updating the flank counters.