Fixing rep.matrix