group docs by courseid & some minor changes