Updated the new algorithm with k calculation.