Fixed bug when some matrices are empty.