Code clarity improvements, and more detailed comments