Implemented depth first search