adding error handling around creating files