Use a loop for polling the close button