refactored socket