fixed freeing bug