Rewrite the loops using the loops module