made some memory fixes