Improved socket closing