moved loops in a macro