Improvements to the connection handling