window add/remove handling improved