Pulled connection code out