proper memory leak fix