improved determination of the cursor position