Make the z_out closer to matching software (still off by one).
Fix typo and off-by-one error.