Refactoring to avoid duplicated code.