added code to avoid duplicate edge creation