optimize key handling