handle empty matrix