adding new matrix replication code