small modification on detection of the repetition direction