fixed calculation of cursor position