Added nested loops into scanner