Key Generation & some bugs removed