Bug fixes for key handlers