fixed the freeing process