Fix bug with the key generator.
Add in the tests.