added undefined/null check snippet