Move connection code to private method

Just a little bit of cleaning :)