After adding the extra point in the sounding data (NZ to NZ+1). This was done in response to having bad data with some of the momentum diagnostics at the top level. Only after this change was I able to get completely uncorrupted netCDF files - no weirdness at any boundary (typically the problem was the top boundary - hence the addition of another vertical layer at the top).