Some strange refactoring - separating socket related code.