loop inversion