added better key handling