small bug fix on function that writes data out