Carried out optimization of Ternary as suggested by Lionello Lunesu.
Merge pull request #1 from tgehr/patch-1

Carried out optimization of Ternary as suggested by Lionello Lunesu.