fix some ressources leaks
Use connection mode also for completion gathering
Fix some tests. Cast to str before displaying