More code cleanup
Separated out socket