fixing memory leaks found in kw
Merge branch 'kw_fix'