cleanup, socket improvements, scope bug