Adding implementation of loop generation.