changed serialization functions for efficiency