add comments and some minor fixes