final versin -v.2 fixed trace map, fixed bug with visited twice