add comments and fix some compilation errors