minor changes and close tcp sockets