simplified and renamed the master loop that replaces rules with html