Refactor to pull out connection.

It's in its own file. It has its own function.