refactor d3js path code