fix serialize/deserialize functions
refactoring