Add serializer and fix bugs.