added global matrix and length & implemented them