Fixed an error in the previous refactoring of the NULL terminating code so that it now doesn't go and clobber memory one beyond that allocated