Tidied up the D3 code