Refactoring for ternary 2