Refactoring to condense similar code.