Added key generation. Needs some work, mostly done.