Refactored JNI Code now to make it easier to read. Follows better best practices!