added matrix traceback optimization