Refactoring.

Changes made to remove loops and make the code more inline with D3
coding practices.