added undefined check