fix bug about 'referenced before assignment'