Improve handling of depth a bit

It turns out Burt Totaro was right...