improved depth calculation