some comments and formatting of code