a lot of fixes, made the cursor use safer