implemented depth first search