builds matrix using lists