Fixed bugs in connections handling