[MAT-329] refactor code to carry JNIEnv pointer through function args where possible.