Added window focus, handled exception