Correct connect and disconnect function