add reference check in debug build when no connections are connected, fix double table ref when replacing an existing key