Repaired many bugs related to connection.