Fix NPEs and write to second data file