Ensure the connection is closed properly.
Some tidying.