added matrix code