Modify close logic