updated Mealy to function correctly