Fixed problem in socket creation + small refactorings