d3 refactoring