tidy up socket closing steps