optimized serialisation, refactoring