Added a condition for not crashing the app with substringWithRage