refactored duplicate logic to utility class