Mostly working

Memory leak on insert duplicate