Adjusted code formatting and added comments