Fixed some connection logic.