Implemented the closeConnection Function