Wrote generic makeKeyState method and tidied up code significantly