Closed socket & Added some type safety