A bunch of fixes involving maps and other stuff

Tested everywhere, I think.

Real commits only start from e3b9771af7b549e192a2bf1f3a239b236cf2593b, where I synced the fork