finished loop algorithms and loop rewrites