added logic for "close" button