Mega commit! Fixes > 5000 warnings and check-style errors.

This fixes a range of trivial and less trivial errors and check-style
infringements. It includes documentation, refactoring, code-removal,
renamings, and even some relocation of code.

It will require thorough testing as a result, but care was taken not to
change any behaviour.