Pull request for all the remaining patches, including the new performance monitors.

Same as before, use const if possible. I haven't checked in detail if that should be possible or not.