Add uniqueness check for edges. Clean-up code.