Undoing merge from fork since it broke some tests.
Fixing unit test for complex key generation