Added nested loop and updated flow chart