Put all file generation into one function. Debugged file generation functions.