added invalid key handling