added undefined check to typecast