Avoid calling toUpperCase on null or undefined
Remove unreachable chaining code