added saveToFile functionality