Brought the loops inside the switch cases.