Trying another method to manage connection, added debug lines