changed K in function, added function for permutations, made for loop to create null in permutation