fixed some memory problems