Edge case fix

Accounted for an edge case where a vertex may have no neighbours; for
example a vertex at the end of a chain.