refactor deserialization code