Refactor to separate creation and serialization