add path check at the close function