Working on main connection loop.