Refactor to add common code into report.js