Refactoring to remove a bit of code duplication