Reworked the connections to be wrapped in context managers.