Connection only when necessary