Added exception for indexOf error