Fixed many connection bugs