update genkey (+minor cleanups)