Added empty matrix check for expand matrix function