refactor key creation