Improved caret position fix