Logarithmic depth support, refactored

Revives the code from #3880 with changes for new file structure