Backporting some code cleanup work from HAMT+