changed to use memory buffer