close logic