create cycle function