add debug + memory leak fix