Fix bug.
Optimize code for JNI callback