forgotten some calls to free, added them