rewrite cycle using chain and repeated