Adding transition matrix logic