Added option to keep empty matrices