refactoring. fixed socket init bug