Moved serialisation into a library of its own.