Refactor connectivity helpers and bugfix