added some comments and formatting