Properly close sockets after use