Got rid of double free, though I left a memory leak in its place