using set for visited