#2 serialize function