Used .classed instead of .attr class. Used undefined instead of null.
Used variable instead of same value several times
bugs detecion and code cleaning