implemented cut-at-repetition function