Fixed a few key-related bugs