Refactor socket