Move invariants out of the loop