Refactor socket module