More tests and fixes for ternary.