Improve key handling