added cycle logic