Refactor code

Clean up the `Connection` class.