Improve error check and serialization process.