modified for ternary system