rewrite cycle as short function