Make word under cursor detection more robust