fixing memory leak with multiple iterations #1