Implemented recursive reachable function