Various changes to align the code with part 2 of the article.