Various fixes to the jni code generation