fix some memory problems