added comments and fixes