move open file out of fileChanged function