Add code to close pop-up window if error is encountered.