refactored, fixed for latest mocha, fixed res.end