Cleanup ternary parsing