Restored keypairs functionality. Fixed a bug in it.

Change-Id: I0fa6d76b07adb09bf464262af3a9bffb00b50fa5