fix pointer logic in MemoryStream