Cleaned up input check for #matrix.