Keep cursor in the correct place