added connection and socket closing