fixed freeing issues