Make xkb target more failsafe, and code cleanup.