Moved key handling logic to its own controller