Refactor some code that had been copy/pasted.