Updated the sample code to use streams for serialization