The key handling code has been simplified.