Fix some crashes and some erratic behavior for the cursor