Remove nested loops by using