Started the dfs function. Wrote everything needed to modify the state.