added undefined value checks