started writing the writeNewFiles() function, many nesting, often douge