incorporate Mark's tensor product code