another refactor for on_demand socket management