Moves socket code to own file