finish first refactor about reduce duplication