Refactoring some repeating code.