added visited tracking and helpful output