Fixed logic errors in connect