there's not too much duplicated code in each block, and the comments are sufficiently verbose (and necessary to explain what's going on) that I don't think we can do away with them