Writing to files fixed