update the logic for auto close