perhaps it should be `k = 2*n` here instead of `k = n*n` ? but I am not sure.
I'll take a more closer look later.