Refactored duplication code