Further improvements to #3 (focus handling).