Key handling code changes