Fix Dict insert bug by using generalized balance function

Also removes now dead code and rearchitects a few things to statically
eliminate possible future bugs.