Fixes #505 (closed)
Also does a few other minor fixes. Reading each commit separately is recommended, or the big deletes make not much sense.
This is just the patched code, I'd guess some other things should be done too, but not sure what. At the very least we should decide an approach together with !473 (merged)