Adjust the logic for closing.