Add initial labels for each row
Remove some unnecessary loops
Replace .attr(class) with .classed()
Position labels correctly