working on freeing functions