Added try-catch for socket opening, and fixed formatting
Fixed formatting issues