some progress on JNI, still not perfect