This is not your fault, but i, j and k are not great variable names. Can you please add a comment explaining what they are?