added comments and made changes for legibility