fix the depth calculation