refactored graph computation