Refactored socket interface