Using a custom stream for serialization