better connection code