bit of helper code for making chained graphical models