Code: Formatting, analysis and minor fixes