refactor key handlers