Fix errors in locale and allocate, and a few other tweaks

Resissue of #2138 with extraneous commits removed.