implemented memstream