Improved formatting and added some comments