refactored out create_socket()