Fixed most key handling problems