Fixes connect and disconnect hadling.