Various technical debt

I suggest reading this one commit at a time!