added comments and made minor changes