fixed some memory related problems