added file error detection