bug fix

Changed the calculation of k