Added K parameter and expanded parameter for outfile and k