refactor socket logic into socket server