bug fixes, unit tests, determinitsic key generation