added comments and renamed local variables to stop using reserved keywords
fixed typo