Upgraded keyboard code