JNI Wrapper: Further improved handle management.