updated unary binary ternary helper function