added socket close and shutdown handling