moved key event handling for debug keys to separate function