added error checking on keycodes