Key handling refactored.