removed matrix init for loop and incorporated into work loop