refactored findCodeVariant to remove conditional complexity and duplication