crash and memory leak fix.