Refactor keyrelay helper