Improve code formatting and style

Improving the code formatting and style to try and improve readability, quality, and maintainability.