Fixed bug in k_generation calculation.