Add Upvalues, fix improper local. fixed elseif and wrong varname.