Added check for last file number when opening a new file