fixed some memory problem