improved: better key handling