Improved backtracking with a map. Still not working with revisited nodes though