Added some error checking to records being written out