more convenient serilizer for streams, added logic for reading matrix