lots of stuff, see commit messages for details