Code duplication refactored