Code: Analysis & minor improvements.
Merge pull request #811 from am11/master

Code: Analysis & minor improvements