move find max depth to util