Added Tri state demo + Optimizing code