putting a cycle function