Fixed insert and memory leak