Code for massing transition matrices