fix variable undefine issues