Tried to remove some memory leaks