fix depth() function