Made some minor changes to KeyGen, including adding comments and a couple of accessor functions.