Refactored adding and removing observers/notifications

Add observers/notifications when added to window, remove them when
window becomes nil.