Clean up connection management.
Cleanup and formatting.