Improve previous memory leak fix