pure -> immutable fixes

https://d.puremagic.com/issues/show_bug.cgi?id=11503
https://d.puremagic.com/issues/show_bug.cgi?id=11909

The actual changes are in 3c0342e and ac4aed5, the rest are just cleanup commits.