Misc: merging, cleaning, code analysis and much more.

@SLaks, please comment especially on the warning fixes and code analysis fixes.