Own implementation of intuitive tristate logic