Added error checking to d3.js script