Changed the position of the connection check.