fix repeating messages algorithm