optimized k_nn and by adding normalize table function