Code: Formatting, analysis and minor fixes.
Merge pull request #788 from am11/master

Code: Formatting, analysis and minor fixes