Flexible key handling