More elegant connection code