Ensure file access when writing to files
Fix object/array references