added conditions for n and k