updated martrixFunction loop