Check string for nil value

make sure to check the string for nil value before doing the caseInsensitiveCompare, otherwise this could introduce a bug.