Fix cycle function