added comments and formatting