generic dfs procedure skeleton