tabs to spaces, whoops
add check for already visited state to best first, includes more pathological test case that exposed the need for this