better logging and waiting for process to close files