better handling of window click event