It took a bit to understand why on earth this script was only partially working before giving up early on. Turns out one of the element removals didn't check to make sure an element (br) existed first, probably because back then, it always existed. Now, not so much. So I added an if statement to prevent the error.