I think I'll move all the common, redundant lines of code in these three blocks outside the `if`s.