Added enum KeyState. Minor code improvements.