Fixed file open bugs