Added validation for writing the empty string.