Fixed bug for k's greater than 1