fix freeing bug