Fix to avoid memory leak