some changes to detect duplicate connection