Fix encode for empty.
Fix serialization.