solved bug with total_num = 0 after first tunnel which used to break things. now fixed.