fixed some memory errors