refactored serialisation