Refactor complex ternary operation

Change-Id: I1b6cc1cf0348bc7e19f9f327c7a3d6d936cfaaf2
Merge "Refactor complex ternary operation"