nested loop for baum welch