handle special case with only one row or one column