rearranged key input stuff, added some logging