Extract serializer and unserializer function, see #32