Refactored minor graph code
Added Jasmine tests for new code