Fix #18

This just backports the relevant code from `dict.jl`.