Refactors the getOrAddVertex into two separate methods.