restructured d3 drawing function