Minor refactor to create generate key