Improved formatting and comments added