Updated class to check for open connections first, then create a new one if needed