Updated JS to make sure an attribute exists before attempting to access a deeper nested attribute.