code refactoring for keys