added closeEvent function