modified the constructor to raise an exception on empty matrices