refactor DRY code