added visited checks