Implementing the closeConnection Function