fix error of undefind ref[idx]