Large refactoring, split into some more libs. Serialisation now works.