fixed reopening the file with wrong flags