slight modifications in generate_keys function