Updated KSDensity JNI function

Becoming one massive function by the looks of it, but should have it
working tomorrow.