Non-nested loops working