Fix formatting issues, and code layout improvements to conform to coding guidelines