Slight improvement to visited labelling logic