introduce undefine and fix some logic.