added matrix calc part