fixed the cursor loop condition