refactor work with socket