There must be a way to extract this little snippet of code into something reusable.