need help modifying for max depth