fix double free errors