Improved the formatting and added some comments.