Fix multi-level add and remove; thanks @icecrime!

This is backported from the vendor directory in the shykes/docker extensions branch.