Working implementation of keypair; more abstraction, better organization