cleaned up the file generating code a bit to make it more testable