fix bug of branch function