Added handling of lostfocus.