Bugfix in SerializeToStream + Unit tests