fix broken saveToFile method.