Fix errors on close