added cycle function