changed to dfs to fix bug in used set