Fixed C code for kernel_weights and replaced R version with corrected C version.