Added functions for saveToFile, additional extrapolation of previous code into cleaner, concise functions.