cleanup code for socket