fixed bad free logic