fixed some memory issues