Code: Formatting and minor improvements.
Merge pull request #755 from am11/master

Code: General fixes and improvements