Refactor for single-responsibility and DRY.