simplify the code. (flatten (repeat ...)) => (cycle ...)