File output with restart logic fixed.