reorganize the socketshandler code