CR changes: added indent and spaces between []
CR changes: changed the condition so undefined will not break anything
CR changes: added spaces between []