Made k an input argument