Better incorporating of aes into the generator, fixed issue with generate_ending.