bugfix for socket bind and other tidying