Fix bug when opening a new file