ternary version