Adding a closing function to reset connection