Factored keyboard code into separate class