Made recursive, moved keycodes into dictionary.