ternary ghetto fix