fixed handling if k = 0