extensive rewrite of grader.js