Fixed undef handling in opt_reduce