fixed some memory leak problems