Better environment management in unification

Also properly guard !!s so that if there is a scope error, you get an
error message rather than a crash (though no guarantees the error
message will be much use...)

Fixes #738, #600 and #891 (and possibly more...)