proper handling of ToBytes for null value