Added some try/catch and other checks to fix some crashes on Android.