updated cycle function