Improving memory leak