this code block is repeated often enough that a single function that does it for you seems warranted.