implementing the close connection function.