Refactor socket optimization by mixin