add private key method

Also minor refactoring/code cleanup