Complete serialization implementation
Fix minor bug